package common.controls.tooltips.backpack
{
	import asset.global.tooltips.BackpackClothingTipsAsset;
	import asset.global.tooltips.BackpackTipsAsset;
	
	import cn.flashk.controls.Image;
	
	import common.controls.item.ItemContainer;
	import common.controls.item.ItemShortcut;
	import common.controls.item.attribute.ItemAttribute;
	import common.controls.tooltips.IToolTipsRender;
	import common.controls.tooltips.ToolTips;
	import common.controls.utils.DateUtils;
	
	import config.Path;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	
	
	/**  
	 * 
	 * @author carrey
	 * */ 
	public class BackpackTipsRenderer implements IToolTipsRender
	{
		private static const ORIGIN:Point = new Point();
		private var _view:BackpackTipsAsset;
		private var _viewClothing:BackpackClothingTipsAsset;
		private var img:ItemShortcut;
		
		public function BackpackTipsRenderer()
		{
		}
		public function getDisplayObject(target:InteractiveObject, data:Object):DisplayObject
		{
			var con:ItemContainer=target as ItemContainer;
			if(con==null||con.item==null)return null;
			
			var asset:Sprite;
			
			if(con.item.attribute.type == 0)
			{
				if(_view == null)
				{
					_view = new BackpackTipsAsset();
					
					
				}
				asset = _view;
				_view.txtName.text = con.item.attribute.name;
				_view.txtLevel.text = con.item.attribute.useLevel.toString();
				_view.txtBind.text = con.item.attribute.bindType.toString();
				_view.txtTime.text = DateUtils.getTimeFormatFromSeconds44(con.item.attribute.activateTime);
				_view.txtDescription.text = con.item.attribute.description;
				_view.txtCurrencyNum.text = con.item.attribute.currencyNum.toString();
				_view.mcCurrencyType.visible = con.item.attribute.currencyNum>0;
				_view.mcCurrencyType.gotoAndStop(con.item.attribute.containerType+1);
				if(_view.imgItem.numChildren>0)
				{
					_view.imgItem.removeChildAt(0);
				}
				img = con.getItemShortcut();
				if(img)
				{
//					img.setSize(_view.imgItem.width,_view.imgItem.height);
					_view.imgItem.addChild(img);
				}
				
				
				
			}else{
				if(_viewClothing == null)
				{
					_viewClothing = new BackpackClothingTipsAsset();
					_viewClothing.btnSubmit.addEventListener(MouseEvent.CLICK,onSubmit);
				}
				asset = _viewClothing;
				_viewClothing.txtName.text = con.item.attribute.name;
				_viewClothing.txtLevel.text = con.item.attribute.useLevel.toString();
				_viewClothing.txtBind.text = con.item.attribute.bindType.toString();
				_viewClothing.txtTime.text = DateUtils.getTimeFormatFromSeconds44(con.item.attribute.activateTime);
				_viewClothing.txtDescription.text = con.item.attribute.description;
				_viewClothing.txtCurrencyNum.text = con.item.attribute.currencyNum.toString();
				_viewClothing.mcCurrencyType.visible = con.item.attribute.currencyNum>0;
				_viewClothing.mcCurrencyType.gotoAndStop(con.item.attribute.containerType+1);
				
				_viewClothing.txtCharm.text = con.item.attribute.charm.toString();
				_viewClothing.txtSex.text = getSex(con.item.attribute.sex);
				
				_viewClothing.mcState.visible=false;
				_viewClothing.mcState.stop();
				if(_viewClothing.imgItem.numChildren>0)
				{
					_viewClothing.imgItem.removeChildAt(0);
				}
				img = con.getItemShortcut();
				if(img)
				{
//					img.setSize(_viewClothing.imgItem.width,_viewClothing.imgItem.height);
					_viewClothing.imgItem.addChild(img);
				}
			}
			
			
			
			
			var p:Point = target.localToGlobal(ORIGIN);
			p.x += target.width+2;
			
			ToolTips.setDisplayDefaultLocatiion(asset, p,0,0);
			
			return asset;
		}
		private function onSubmit(evt:MouseEvent):void
		{
			
		}
		private function getSex(v:uint):String
		{
			if(v==0)
			{
				return "女"
			}else if(v==1)
			{
				return "男"
			}
			return "无"
		}
	}
}